﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class Solution238
{
    public int[] ProductExceptSelf(int[] nums)
    {
        int len= nums.Length;
        int[] premul = new int[len];//前面的数的乘积
        premul[0] = nums[0];
        for (int i = 1; i < nums.Length; i++)
        {
            premul[i] = nums[i]* premul[i-1];
        }
        int[] nextmul = new int[len];//后的数的乘积
        nextmul[len - 1] = nums[len-1];
        for (int i = len - 2; i >= 0; i--)
        {
            Console.WriteLine(nextmul[i + 1]);
            nextmul[i] = nums[i] * nextmul[i + 1];
        }
        int[] res = new int[len];//前面的数的乘积
        res[0] = nextmul[0 + 1];
        res[nums.Length - 1] = premul[nums.Length - 1 - 1];
        Console.WriteLine("premul[i]:  ");
        for (int i = 0; i < nums.Length; i++)
        {
            Console.Write("  " + premul[i]);
        }
        Console.WriteLine();
        Console.WriteLine("nextmul[i]:  ");
        for (int i = 0; i < nums.Length; i++)
        {
            Console.Write("  "+ nextmul[i]);
        }
        
        for (int i = 1; i < nums.Length - 1; i++)
        {

            res[i] = premul[i - 1] * nextmul[i + 1];
        }
        return res;

    }
}
class Program238
{
    static void Main238(string[] args)
    {
        Solution238 solution = new Solution238();
        int[] nums = [1, 2, 3, 4];
        int[] res = solution.ProductExceptSelf(nums);
        for (int i = 0; i < nums.Length; i++)
        {
            Console.WriteLine(res[i]);
        }
    }
}
